﻿import request from '/@/utils/request';
enum Api {
  AddVisitLog = '/api/visitLogExtend/add',
  DeleteVisitLog = '/api/visitLog/delete',
  UpdateVisitLog = '/api/visitLogExtend/update',
  SaveVisitLog = '/api/visitLog/save',
  PageVisitLog = '/api/visitLog/page',
  ExportVisitLog = 'api/visitLog/export',
  ImportUrl= 'api/visitLog/import',
  downLoadTemplate = 'api/visitLog/TemplateDown',
  UploadVimg = '/api/visitLog/UploadVimg',
  UploadDocImg = '/api/visitLog/UploadDocImg',
  UploadGoodsInfo = '/api/visitLog/UploadGoodsInfo',
  GetSysOrgDeptIdDropdown = `/api/visitLog/SysOrgDeptIdDropdown`,
  GetSysUserLeaderIdDropdown = `/api/visitLog/SysUserLeaderIdDropdown`,
}

//导出訪客記錄
export const exportVisitLogExcel=(params?:any)=>
	request({
		url:Api.ExportVisitLog,
		method:'post',
		data:params,
		responseType: 'blob'
	});

// 增加訪客記錄
export const addVisitLog = (params?: any) =>
	request({
		url: Api.AddVisitLog,
		method: 'post',
		data: params,
	});

// 删除訪客記錄
export const deleteVisitLog = (params?: any) => 
	request({
			url: Api.DeleteVisitLog,
			method: 'post',
			data: params,
		});

// 编辑訪客記錄
export const updateVisitLog = (params?: any) => 
	request({
			url: Api.UpdateVisitLog,
			method: 'post',
			data: params,
		});

// 保存訪客記錄
export const saveVisitLog = (params?: any) => 
	request({
			url: Api.SaveVisitLog,
			method: 'post',
			data: params,
		});

// 分页查询訪客記錄
export const pageVisitLog = (params?: any) => 
	request({
			url: Api.PageVisitLog,
			method: 'post',
			data: params,
		});

export const importUrl = () => {return Api.ImportUrl;};
export const downLoadTemplate = ()=>{return Api.downLoadTemplate ;};


	/**
	* 上传人臉頭像 
	*/
export const uploadVimg = (params: any) =>
		uploadFileHandle(params, Api.UploadVimg)
	/**
	* 上传證件照片 
	*/
export const uploadDocImg = (params: any) =>
		uploadFileHandle(params, Api.UploadDocImg)
/**
	* 上传物品信息 
	*/
	export const uploadGoodsInfo = (params: any) =>
		uploadFileHandle(params, Api.UploadGoodsInfo)
export const getSysOrgDeptIdDropdown = (model) =>
		request({
		url: `${Api.GetSysOrgDeptIdDropdown}`,
		method: 'post',
		data: model
		});
export const getSysUserLeaderIdDropdown = (model) =>
		request({
		url: `${Api.GetSysUserLeaderIdDropdown}`,
		method: 'post',
		data: model
		});

	export const uploadFileHandle = (params: any, url: string) => { 
	const formData = new window.FormData();
	formData.append('file', params.file);
	//自定义参数
	if (params.data) {
		Object.keys(params.data).forEach((key) => {
			const value = params.data![key];
			if (Array.isArray(value)) {
				value.forEach((item) => {
					formData.append(`${key}[]`, item);
				});
				return;
			}
			formData.append(key, params.data![key]);
		});
	}
	return request({
		url: url,
		method: 'POST',
		data: formData,
		headers: {
			'Content-type': 'multipart/form-data;charset=UTF-8',
			// ts-ignore
			ignoreCancelToken: true,
		},
	});
};
